<br /><br />
<?php 
function ArrToStr($arr){
	$str="";
	if(is_array($arr)){
		$keys=array_keys($arr);
		foreach ($keys as $key){
			$a=$arr[$key];
			if(is_array($a)){
				$str.=ArrToStr($a)."<br />";
			}
			else {
				if($key==="id"){
					$str.="(".$a.")";
				}
				else{
					$str.=$a."<br />";
				}
			}
		}
	}
	else {
		$str.=$arr;
	}
	return $str;
	
}
?>

<div id="view-content">
<a href="/index/backtwo">Go Back</a>
<?php $item=$this->item; ?>
<?php if($item==NULL):?>
<p>Nothing Found!</p>
<?php else :?>
<?php $keys=array_keys($item); ?>
<table  border="1">
	<tr>
		<td>
			<form action="/ItemManager/donate" method="post">
				<input type="submit" value="Donate" />
			</form>
		</td>
	</tr>
	  <?php if(in_array("title", $keys)):?>
<tr><td>Title</td><td><?php echo $item["title"]?></td></tr>
<?php unset($item["title"]);
	  endif;?>
	  <?php if(in_array("names", $keys)):?>
<tr><td>Names</td><td><?php $names=$item["names"]["item"];
		$curName="";
		if(is_array($names)){
			foreach ($names as $name){
				$curName.=$name."; ";
			}
		}else{
		
				$curName.=$names."; ";
		}
		echo $curName;
		?></td></tr>
<?php unset($item["names"]);
	  endif;?>
	  <?php if(in_array("summary", $keys)):?>
<tr><td>Summary</td><td><?php echo $item["summary"]?></td></tr>
<?php unset($item["summary"]);
	  endif;?>
	  <?php if(in_array("description", $keys)):?>
<tr><td>Description</td><td><div style="overflow-y:auto; max-height:100px;" ><?php echo $item["description"]?></div></td></tr>
<?php unset($item["description"]);
	  endif;?>
	  <?php if(in_array("importance", $keys)):?>
<tr><td>Importance</td><td><?php echo $item["importance"]?></td></tr>
<?php unset($item["importance"]);
	  endif;?>
	  	  <?php if(in_array("dimensions", $keys)):?>
<tr><td>Dimensions</td><td><?php 
			$dimensions=$item["dimensions"];
			$curStr="";
			if(is_array($dimensions)){
				$dimensionsKeys=array_keys($dimensions);
				foreach ($dimensionsKeys as $aKey){
					if($dimensions[$aKey]!="None"){
						$curStr.=$aKey.": ".$dimensions[$aKey]."; ";
					}
				}	
			}
			echo $curStr; ?></td></tr>
<?php unset($item["dimensions"]);
	  endif;?>
	  	  <?php if(in_array("terms", $keys)):?>
<tr><td>Terms</td><td><?php 
	$terms=$item["terms"];
	$termsStr="";
	$termItem=$terms=$item["terms"]["item"];
	if(is_array($termItem)){
		foreach ($termItem as $aTerm){
			$termsStr.=$aTerm["term"]."(".$aTerm["id"]."); ";
		}
	}else{
		if(key_exists("term", $terms)&&key_exists("id", $terms)){
			$termsStr.=$aTerm["term"]."(".$aTerm["id"]."); ";
		}
	}
	echo $termsStr; ?></td></tr>
<?php unset($item["terms"]);
	  endif;?>
	  <?php if(in_array("registration_number", $keys)):?>
<tr><td>Registration Number</td><td><?php echo $item["registration_number"]?></td></tr>
<?php unset($item["registration_number"]);
	  endif;?>
	  <?php if(in_array("provenance", $keys)):?>
<tr><td>Provenance</td><td><div><?php
	$provenanceStr="";
	if($item["provenance"]!=null){ 
	$provenanceItems=$item["provenance"]["item"];
	
	if(is_array($provenanceItems)){
		foreach ($provenanceItems as $aProvenanceItem){
			if($aProvenanceItem!=null&&is_array($aProvenanceItem)){
				$provenanceItemKeys=array_keys($aProvenanceItem);
				foreach ($provenanceItemKeys as $aProvenanceItemKey){
					$provenanceStr.=$aProvenanceItemKey.": ".$aProvenanceItem[$aProvenanceItemKey]."; ";
				}
				$provenanceStr.="<br />";
			}
		}
	}
	}
	echo $provenanceStr; ?></div></td></tr>
<?php unset($item["provenance"]);
	  endif;?>
	  <?php if(in_array("thumbnail", $keys)):?>
<tr><td>Thumbnail</td><td><?php if($item["thumbnail"]!=NULL):?><img src="<?php echo $item["thumbnail"]["url"]?>" /><?php endif;?></td></tr>
<?php unset($item["thumbnail"]);
	  endif;?>
	  <?php $multimedias=$this->multimedias; ?>
	  <?php if($multimedias!=null):?>
<tr><td>Multi-Media</td><td><table><tr>
		<?php $imagesCount=0;?>
		<?php for($i=0;$i<count($multimedias);$i++):?>
		<?php $aImage=$multimedias[$i];?>
	  	<td><?php if(in_array(strtolower($aImage["mime_format"]), array("jpeg","png"))):?>
	  		<?php $imagesCount++; ?>
	  				<img src="<?php echo $aImage["images"]["thumbnail"]["url"] ?>" />
	  		<?php endif;?>
	  	</td>
	  	<?php if($imagesCount%4==0&&$imagesCount!=0):?>
	  	</tr><tr>
	  	<?php endif;?>	  	
	  	<?php endfor;?></tr>
</table></td></tr>	  
	  <?php endif;?>
	  <?php $curKes=array_keys($item);?>
	  <?php foreach ($curKes as $bKey):?>
	  <tr><td><?php echo $bKey; ?></td><td><div><?php echo ArrToStr($item[$bKey]);?></div></td></tr>
	  <?php endforeach;?>

</table>
<?php endif;?>
</div>